#!/bin/bash
. ./var
#. ./Tmpdir
Add_Users(){
    #root用户操作
    (id operation && id developer && id admin) &> /dev/null
    if [ $? = 0 ] ;then
	echoGreen "用户已存在，退出脚本……"
#	rm -rf $dir
        exit 6
    else
	(useradd operation  && echo "666666" | passwd --stdin operation) &> /dev/null && echoGreen "operation用户创建成功"
        [ $? != 0 ] && echoRed "未成功创建" && exit 21
	(useradd developer  && echo "developer:666666" | chpasswd) &> /dev/null && echoGreen "developer用户创建成功"
        [ $? != 0 ] && echoRed "未成功创建" && exit 23
	(useradd admin  && echo "admin:666666" | chpasswd) &> /dev/null && echoGreen "admin用户创建成功"
        [ $? != 0 ] && echoRed "未成功创建" && exit 23
	#给admin普通用户授权
        sed -i.bak '/^root/a\admin  ALL=(ALL)       ALL' /etc/sudoers
cat > /root/.bashrc << EOF
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias untar='tar xvf '
alias grep='grep --color=auto'
alias getpass="openssl rand -base64 20"
# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi
#命令提示符
#export PS1="\[\e[1;35m\][\u@\h \w]\\\$\[\e[0m\]"
EOF
sed -i '/export PATH/aexport PS1="\\[\\e[1;35m\\][\\u@\\h \\w]\\\\$\\[\\e[0m\\]"' /root/.bash_profile
    source /root/.bashrc
    source /root/.bash_profile

#operation init
    echoYellow "开始初始化operation用户"
cat > /home/operation/.bashrc << EOF
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# User specific aliases and functions
#export PS1="\[\e[1;35m\][\u@\h \w]\\\$\[\e[0m\]"
EOF
sed -i '/export PATH/aexport PS1="\\[\\e[1;35m\\][\\u@\\h \\w]\\\\$\\[\\e[0m\\]"' /home/operation/.bash_profile
    chown operation.operation /home/operation/.bashrc
    source /home/operation/.bash_profile
    mkdir /home/operation/.ssh && chmod 700 /home/operation/.ssh
cat > /home/operation/.ssh/authorized_keys << EOF
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDdEw+PsiXnaM7feJ1cgpBFksWMM33QGAIB2E5fW5d85Cc/+4I0+2Som+ukV9uCxyuUs1xexqBKuT7PdQrxzHgUwnevJFFhFMagnCR00HKRjpmCC7QAK48SsvdbU/6hvGBsaTH8V0eipNgatnhFnnGGkDLtqw/aSjWbdT1dfAgHbuACzko1cnc0JjP6r+DGImWlNn+BKO2UziI5w0G1J7k2/WPFldj++2Ja6Q7clHB1FNz06mDxSfCmenrophaFjnvzwNoPITs2CTTp/yh+uvMZTaqcYfc93dy2fyvy+GsVH6+WjQVLxyGRIKxYsTh+spN9ngxHWqV7RTNHTbBEj1t3 operation@jump
EOF
    chmod 600 /home/operation/.ssh/authorized_keys && chown -R operation.operation /home/operation/.ssh
    echoGreen "operation用户初始化完毕！"

#developer init
    echoYellow "开始初始化developer用户"
    mkdir /home/developer/.ssh && chmod 700 /home/developer/.ssh
cat > /home/developer/.ssh/authorized_keys << EOF
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC1Cy+UURmFDlxT/RQcz7m2mws82Bf5ZYFD/RwjYNqkPDlayGihSU7LBfdgDKrJuaYt62SyGveV88z6xM+NzaPH6gZAWJr1S+lUBz27TLoBenMKfMahsrqI1eQ/Lic7wOLhiP3UOuFvG+y9udRNt56FiQsmrNzpHWPHLczpei4flPaGk7/Xv6yUmuEhRaa2itorA9qnUD2ZlGyTWaCWyroEdffeypq38aBFVSyKi3c3kbokx8anN6YFzNlZBvjbGDUzK6eOs3ufOiwJHdokTkMjBW9LtAbJPAEBzcSmozgi5Eg7Yn0TBu5RZ12xBBvXU8MHGGuYmjYeJjMyUS6e/8KX developer@jump
EOF
    chmod 600 /home/developer/.ssh/authorized_keys && chown -R developer.developer /home/developer/.ssh
    echoGreen "developer用户初始化完毕"

    echoGreen "用户初始化完毕,用户的初始登陆密码为666666.根据实际情况进行更改"
fi
#    rm -rf $dir

#admin init
    echoYellow "开始初始化admin用户"
cat > /home/admin/.bashrc << EOF
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# User specific aliases and functions
#export PS1="\[\e[1;35m\][\u@\h \w]\\\$\[\e[0m\]"
EOF
sed -i '/export PATH/aexport PS1="\\[\\e[1;35m\\][\\u@\\h \\w]\\\\$\\[\\e[0m\\]"' /home/admin/.bash_profile
    chown admin.admin /home/admin/.bashrc
    source /home/admin/.bash_profile
    mkdir /home/admin/.ssh && chmod 700 /home/admin/.ssh
cat > /home/admin/.ssh/authorized_keys << EOF
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDdEw+PsiXnaM7feJ1cgpBFksWMM33QGAIB2E5fW5d85Cc/+4I0+2Som+ukV9uCxyuUs1xexqBKuT7PdQrxzHgUwnevJFFhFMagnCR00HKRjpmCC7QAK48SsvdbU/6hvGBsaTH8V0eipNgatnhFnnGGkDLtqw/aSjWbdT1dfAgHbuACzko1cnc0JjP6r+DGImWlNn+BKO2UziI5w0G1J7k2/WPFldj++2Ja6Q7clHB1FNz06mDxSfCmenrophaFjnvzwNoPITs2CTTp/yh+uvMZTaqcYfc93dy2fyvy+GsVH6+WjQVLxyGRIKxYsTh+spN9ngxHWqV7RTNHTbBEj1t3 operation@jump
EOF
    chmod 600 /home/admin/.ssh/authorized_keys && chown -R admin.admin /home/admin/.ssh
    echoGreen "admin用户初始化完毕！"
}
